<template>
  <div>
    <div>
      <el-table
        border
        ref="multipleTable"
        :data="toApplyData"
        tooltip-effect="dark"
        style="width: 100%;cursor: pointer"
      >
        <el-table-column
          prop="adminName"
          label="申请人"
        >
        </el-table-column>
        <el-table-column
          prop="applyDate"
          label="申请日期"
        >
        </el-table-column>

        <el-table-column
          prop="roomStatus"
          label="申请状态"
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.applyStatus === 0" type="warning">
              待审批
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="leaveReason"
          label="请假原因"
        >
        </el-table-column>
        <el-table-column
          prop="firstDate"
          label="请假开始日期"
        >
        </el-table-column>
        <el-table-column
          prop="lastDate"
          label="请假结束日期"
        >
        </el-table-column>

        <el-table-column
          prop="createTime"
          label="创建时间"
        >
        </el-table-column>
        、<el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="accept(scope.$index, scope.row)">同意</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="refuse(scope.$index, scope.row)">拒绝</el-button>
        </template>
      </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import leaveAPI from "../../../api/leave";
export default {
  name: "ToLeaveApply",
  data() {
    return {
      userInfo: JSON.parse(sessionStorage.getItem('userInfo')),
      toApplyData:[],
      role: 0,
    }
  },
  methods:{
    getData(){
      this.checkRoles(this.userInfo.roles);

    },
    getApply(){
      // 主管
      if (this.role === 4) {
        console.log("4进来了");
        console.log(this.userInfo);
        leaveAPI.getApplyByDirector(this.userInfo.departmentId).then(res => {
          if (res) {
            console.log("4进来了");
            this.toApplyData = res.data.obj
            console.log("44444");
            console.log(res.data);
          }
        })
      }
      if (this.role === 3) {
        console.log("3进来了");
        console.log(this.userInfo.departmentId);
        leaveAPI.getApplyByManager(this.userInfo.departmentId).then(res => {
          if (res) {
            this.toApplyData = res.data.obj
            console.log("33333");
            console.log(res.data);
          }
        })
      }

    },
    checkRoles(roles) {
      roles.map(item => {
        if (item.id == 3 || item.id == 4) {
          this.role = item.id;
          this.getApply()
          console.log(this.role);
          return;
        }
      })
    },
    accept(index, row){
      leaveAPI.acceptApplyStatus(row).then(res => {
        if (res){
          this.getData()
        }
      })
    },
    refuse(index, row) {
    }
  },
  mounted() {
    this.getData();
  }
}
</script>

<style scoped>

</style>
